<?php

use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserWechatsTable extends Migration
{
    protected  $table = 'user_wechats';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if(!Schema::hasTable($this->table)){
            Schema::create($this->table, function (Blueprint $table) {
                $table->charset = 'utf8mb4';
                $table->collation = 'utf8mb4_general_ci';
                $table->comment = '用户微信绑定表';
                $table->increments('id')->comment('主键');
                $table->unsignedInteger('uid')->nullable()->unique()->comment('用户id, null为未绑定状态');
                $table->char('openid',28)->unique()->comment('openid');
                $table->char('unionid',28)->nullable()->unique()->comment('unionid');
                $table->string('nickname', 255)->default('')->comment('昵称');
                $table->unsignedTinyInteger('gender')->default(0)->comment('性别值为1时是男性，值为2时是女性，值为0时是未知');
                $table->string('city', 50)->default('')->comment('城市');
                $table->string('province', 50)->default('')->comment('省份');
                $table->string('country', 50)->default('')->comment('国家');
                $table->string('head', 255)->default('')->comment('用户头像');
                $table->timestamps();
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (Schema::hasTable($this->table)) {
            Schema::dropIfExists($this->table);
        }
    }
}